layui.use(top.layuiuse, function () {
    var $ = layui.jquery;
    var kaAjax = layui.kaAjax;
    var kahtml = layui.kahtml;
    var kaBgUrl = layui.kaBgUrl;
    var watermark = layui.watermark;
    var kaPublic = layui.kaPublic;
    var kaGrid = layui.kaGrid;
    //公共
    var bodyUrl = kaPublic.initBodySetUp();
    //加载水印
    loadingWatermark(watermark);
    //初始化ID
    var registerkey = kaRegisterPrimaryKey.registerId(["treeAndDataGrid", "treeAndDataGridLeft", "treeAndDataGridRight", "treeAndDataGridLeft1"]);
    if (registerkey.judge) {
        var kahtml = layui.kahtml;
        // 表格分栅格
        gridHtmlData = {
            id: registerkey.ids[0],
            colSpace: 10, // Grid 间隔
            list: [{
                id: registerkey.ids[1],
                style: "width: 300px;height: 100%;",
                colXs: 3
            }, {
                id: registerkey.ids[2],
                style: "width: calc(100% - 300px);height: 100%;",
                colXs: 8
            }] // 循环数据
        }
        kahtml.getTemplateHtml("grid", gridHtmlData);
        // 面板1
        panelHtmlData1 = {
            id: registerkey.ids[1],
            list: [{
                id: registerkey.ids[3],
                style: "padding-left: 10px;padding-right: 10px;height: 100%;"
            }]
        }
        kahtml.getTemplateHtml("panel", panelHtmlData1);
        // 面板2 渲染 树结构
        var treeParams = {};
        layui.kaAjax.ajax(layui.kaBgUrl.url("getTreeAndDataGridTree"), function (rs) {
            if (rs.code == 200) {
                treeParams = rs.data;
            } else {
                layui.kaMsg.error("请求失败," + rs.msg, JSON.stringify(rs));
            }
        }, {id: bodyUrl.id});
        var kaTreekeyId = 'treeAndDataGridTree';
        $("#" + registerkey.ids[3]).html(layui.kaTree.getHtml(kaTreekeyId, 'label'));
        // 加载左侧树Tree
        layui.kaTree.init({
            id: kaTreekeyId,
            url: treeParams.url,
            customName: { id: treeParams.id, title: treeParams.title, children: treeParams.children },
            kjQueryClick: treeParams.kjQueryClick,
            click: function (obj) {
                var $ = layui.$;
                $(this.elem).find(".kaLayuiTreeSet").each(function (params) {
                    $(this).removeClass("kaLayuiTreeSet");
                })
                $(obj.elem[0]).addClass("kaLayuiTreeSet");
                var kjQueryClick = this.kjQueryClick;
                kjQueryClick.value = obj.data.id;
                layui.kaGridTopButton.kjQueryClick(2, kjQueryClick, this);
            }
        });
        layui.kaTree.render('treeAndDataGridTree');
        $("#find" + kaTreekeyId + "TreeInput").keyup(function (event) {
            layui.kaTree.render('treeAndDataGridTree');
        });
        // 加载树完成 
        // 加载table
        $("#" + registerkey.ids[2]).html(`<div id="treeAndDataGridTable" style="height: 100%;background: #ffffff9e;"><div id="kaDataGridId"></div></div>`);
        //加载表格
        var kaGridParamsData = treeParams.kaGridParams;
        kaGridParamsData["height"] = "full-7";
        kaGridParamsData["bodyUrlId"] = bodyUrl.id;
        var kaGridParams = kaGrid.getKaGridParams(kaGridParamsData);
        kaGrid.init(kaGridParams);
    }
})